package com.hzlj.position.job.rest;

import cn.hutool.core.date.DateUtil;
import com.fz.common.base.core.date.DateUtils;
import com.fz.stat.common.util.StatRestUtil;
import com.hzlj.position.config.config.PositionConfig;
import com.hzlj.position.job.common.dto.noticeJob.NoticeJobParamsDTO;
import com.hzlj.position.locate.common.dto.reportCommon.AbnMissingStatDTO;
import com.hzlj.position.locate.common.dto.reportCommon.ReportInitiativeStatDTO;
import com.hzlj.position.locate.common.dto.reportCommon.ReportInspectionStatDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class StatRest {
    @Resource
    private PositionConfig positionConfig;

    /**
     * 人脸签到状态统计-按机构
     */
    public List<ReportInitiativeStatDTO> statInitiativeByReportStatus(NoticeJobParamsDTO params,
                                                                      String jgCode,
                                                                      Date day) {
        return StatRestUtil.list(positionConfig.getStatService().getUrl(),
                "sqlIds=" + params.getSqlIds()
                        + "&jgCode=" + jgCode
                        + "&jgCodeLength=" + params.getJgCodeLength()
                        + "&startTime=" + DateUtil.formatDateTime(DateUtil.beginOfDay(day))
                        + "&endTime=" + DateUtil.formatDateTime(DateUtil.endOfDay(day)),
                ReportInitiativeStatDTO.class);
    }

    /**
     * 自动点验状态统计-按机构
     */
    public List<ReportInspectionStatDTO> statInspectionAutoByReportStatus(NoticeJobParamsDTO params,
                                                                          String jgCode,
                                                                          String reportType,
                                                                          Date day) {
        String belongDay = DateUtils.formatShortDate(day);
        return StatRestUtil.list(positionConfig.getStatService().getUrl(),
                "sqlIds=" + params.getSqlIds()
                        + "&belongDay=" + belongDay
                        + "&jgCode=" + jgCode
                        + "&jgCodeLength=" + params.getJgCodeLength()
                        + "&reportType=" + reportType
                        + "&jzId=",
                ReportInspectionStatDTO.class);

    }


    /**
     * 失联核查-按机构
     */
    public List<AbnMissingStatDTO> statAbnMissing(NoticeJobParamsDTO params,
                                                  String jgCode,
                                                  Date day) {
        return StatRestUtil.list(positionConfig.getStatService().getUrl(),
                "sqlIds=" + params.getSqlIds()
                        + "&jgCode=" + jgCode
                        + "&jgCodeLength=" + params.getJgCodeLength()
                        + "&belongDayGte=" + DateUtils.formatShortDate(DateUtil.offsetDay(day, -params.getAbnMissingDays()))
                        + "&belongDayLte=" + DateUtils.formatShortDate(day)
                        + "&abnMissingDays=" + params.getAbnMissingDays(),
                AbnMissingStatDTO.class);
    }

}
